Skip to content

Conversation

@netroms
Copy link
Contributor

@netroms netroms commented Jan 7, 2026

This pull request disables the query cache for OrganisationUnit objects to improve performance and avoid issues with N+1 queries during hydration of OrganisationUnit objects. The N+1 issue seen when doing OrganisationUnit queries was caused by Hibernate when it was hydrating the objects from the query cache and needed to set the parent, which is only represented by an ID in the cache, and hence it needed to fetch the whole object from the database for each result object.

Signed-off-by: Morten Svanaes <msvanaes@dhis2.org>
@netroms netroms marked this pull request as ready for review January 7, 2026 13:49
Copy link
Contributor

@david-mackessy david-mackessy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always good to avoid the n+1 - nice 👍

Are we getting to a place where OrgUnits are never cached now?
Are we fully aware of any wider implications of the change? (All of these may not be relevant)

  • potential downsides of the change
  • some calls will be better, some will be worse
  • many more DB queries for one of the most queried objects in the system

We have the ability to add tests that check the number of SQL queries executed - could it be useful here?

@netroms netroms requested a review from a team as a code owner January 27, 2026 17:33
@netroms netroms marked this pull request as draft January 27, 2026 17:37
Signed-off-by: Morten Svanaes <msvanaes@dhis2.org>
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants